import type { AppRouteModule, Recordable } from '@/router/types'

// import.meta.glob() 直接引入所有的模块 Vite 独有的功能
const modules = import.meta.glob('./modules/**/*.ts', { eager: true });
const basicRouteModuleList: AppRouteModule[] = [];
const homeRouteModuleList: AppRouteModule[] = [];

// 加入到路由集合中
Object.keys(modules).forEach((key) => {

    // 获取模块中的 default export
    const mod = (modules as Recordable)[key].default || null;

    if (mod != null) {
        const modList = Array.isArray(mod) ? [...mod] : [mod];
        if (key.startsWith('./modules/home/')) {
            // 添加 home 中的路由
            homeRouteModuleList.push(...modList);
        }
        else {
            // 将模块中的 AppRouteModule 添加到基础路由
            basicRouteModuleList.push(...modList);
        }
    }
});

export const basicRoutes = [
    ...basicRouteModuleList
]

export const homeRoutes = [...homeRouteModuleList]